<template>
	<view style="margin: 0 20rpx;">
		<!-- 瀑布流布局列表 -->
		<view>
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<!-- rightList leftList -->
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index" @click="goPage(item.id,item)">
						<u-lazy-load :image="item.goodImg+'!idx'" :index="index" mg-mode="widthFix"></u-lazy-load>
						<view style="margin: 10rpx;">
							<view style="font-size: 28rpx;font-weight: bold;">{{item.car_Type_Name}}</view>
							<view class="demo-title">
								{{item.configuration_Name}}
							</view>
							<view class="flex">
								<view class="demo-tag">
									<view class="demo-tag-owner" v-if="item.proprietary">
										自营
									</view>
								</view>
								<view class="demo-tag">
									<view class="demo-tag-text" v-if="item.rentOut">
										以租代售
									</view>
									<view class="demo-tag-sf" v-if="item.down_Payment">
										一成首付
									</view>
									<view class="demo-tag-j" v-if="item.loans">
										巨能降
									</view>
								</view>
							</view>
							<!-- 巨能降 -->
							<view class="demo-shop">
								指导价：<text class="demo-price3" v-if="!item.loans">{{item.factory_Price}}</text>
								<text class="demo-price2" v-if="item.loans">{{item.factory_Price}}</text>
							</view>
							<view class="flex flex-jc-sb" v-if="!item.loans">
								<view class="demo-price">
									月供<text style="font-size: 26rpx;font-weight: bold;">{{item.monthlyPayments}}</text>
								</view>
								<view class="demo-price">
									首付<text style="font-weight: bolder;font-size: 26rpx;">{{item.downPayment}}</text>
								</view>
							</view>
							<!-- 巨能降 -->
							 <!-- :class="isLeft?'flex-jc-sb':'flex-jc-fe' " -->
							<view class="flex flex-ai-c" v-if="item.loans">
								<view class="demo-price" style="margin-right: 10rpx;">
									<text :style="isLeft?'font-weight: bolder;font-size: 30rpx;':'font-weight: bolder;font-size: 30rpx;margin-right:10rpx'">{{item.client_Price}}</text>
								</view>
								<view class="demo-price">
									<u-icon name="arrow-downward" color="#38AA0B" size="18"></u-icon>
									<text style="font-weight: bolder;color: rgb(53,176,14); font-size: 30rpx;">{{item.difference}}</text>
								</view>
							</view>
						</view>

					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index" @click="goPage(item.id,item)">
						<u-lazy-load :image="item.goodImg+'!idx'" :index="index" mg-mode="widthFix"></u-lazy-load>
						<view style="margin: 10rpx;">
							<view style="font-size: 28rpx;font-weight: bold;">{{item.car_Type_Name}}</view>
							<view class="demo-title">
								{{item.configuration_Name}}
							</view>
							<view class="flex">
								<view class="demo-tag">
									<view class="demo-tag-owner" v-if="item.proprietary">
										自营
									</view>
								</view>
								<view class="demo-tag">
									<view class="demo-tag-text" v-if="item.rentOut">
										以租代售
									</view>
									<view class="demo-tag-sf" v-if="item.down_Payment">
										一成首付
									</view>
									<view class="demo-tag-j" v-if="item.loans">
										巨能降
									</view>
								</view>
							</view>
							<view class="demo-shop">
								指导价：<text class="demo-price3" v-if="!item.loans">{{item.factory_Price}}</text>
								<text class="demo-price2" v-if="item.loans">{{item.factory_Price}}</text>
							</view>
							<!-- 没有巨能降 -->
							<view class="flex flex-jc-sb" v-if="!item.loans">
								<view class="demo-price">
									月供<text style="font-size: 26rpx;font-weight: bold;">{{item.monthlyPayments}}</text>
								</view>
								<view class="demo-price">
									首付<text style="font-weight: bolder;font-size: 26rpx;">{{item.downPayment}}</text>
								</view>
							</view>

							<!-- 巨能降 -->
							<view class="flex flex-ai-c" v-if="item.loans">
								<view class="demo-price" style="margin-right: 10rpx;">
									<text :style="isLeft?'font-weight: bolder;font-size: 28rpx;':'font-weight: bolder;font-size: 28rpx;margin-right:10rpx'">{{item.client_Price}}</text>
								</view>
								<view class="demo-price">
									<u-icon name="arrow-downward" color="#38AA0B" size="18"></u-icon>
									<text style="font-weight: bolder;color: rgb(53,176,14); font-size: 28rpx;">{{item.difference}}</text>
								</view>
							</view>
						</view>


					</view>
				</template>
			</u-waterfall>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			carlist: {
				type: Array,
				default: () => []
			},
			isLeft: {
				type: Boolean,
				default: true
			},
		},
		data() {
			return {
				flowList: []
			};
		},
		watch: {
			// 监听车品列表
			carlist(val) {
				// console.log('监听数组', val)
				/* 
				 * if: 如果车品列表为空，则把瀑布流组件的数据清空
				 * 
				 * else: 如果车品列表有数据，则先把瀑布流组件的数组数据清空
				 * 然后调用处理数组的方法，该方法处理瀑布流组件用到的数组
				 * 
				 */
				if (val.length === 0) {
					this.flowList = []
					this.$refs.uWaterfall.clear()
				} else {
					this.flowList = []
					this.addRandomData()
				}
			}

		},
		methods: {
			million(value) { //过万处理
				let num
				if (value > 9999) { //大于9999显示x.xx万
					num = ((value / 1000) / 10).toFixed(2) + '万'
				} else if (value <= 9999 && value >= -9999) {
					num = value + '元'
				} else if (value < -9999) { //小于-9999显示-x.xx万
					num = -((Math.abs(value) / 1000) / 10).toFixed(2) + '万'
				}
				return num
			},
			addRandomData() {
				for(let i in this.carlist){
					this.carlist[i].downPayment = this.million(this.carlist[i].downPayment)
					this.carlist[i].monthlyPayments = this.million(this.carlist[i].monthlyPayments)
				}
				this.flowList = JSON.parse(JSON.stringify(this.carlist))
			},
			goPage(id, item) {
				console.log(id, item)
				if (item.loans) {
					uni.navigateTo({
						url: '/pages_commodity/giantnengjiangDetails/giantnengjiangDetails?goodid=' + id
					})
				} else {
					uni.navigateTo({
						url: '/pages_commodity/sourceDetails/sourceDetails?goodid=' + id
					})
				}

			}
		}
	};
</script>

<style lang="scss" scoped>
	/deep/.u-lazy-item {
		border-top-left-radius: 10rpx !important;
		border-top-right-radius: 10rpx !important;
	}

	//默认图
	.defaultMap {
		padding-top: 100rpx;
		width: 750rpx;
		height: 85vh;
		text-align: center;

		image {
			width: 263rpx;
			height: 277rpx;
		}

		.texna {
			font-size: 28rpx;
			color: #999999;
		}
	}

	.wrap {
		width: 100%;

	}

	//瀑布流
	.demo-warter {
		background-color: #fff;
		border-radius: 8px;
		margin: 5px;
		box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.12);
		// padding: 8px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 25rpx;
		// margin-top: 5px;
		display: -webkit-box;
		color: $u-main-color;
		overflow: hidden;
		text-overflow: ellipsis;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
		// margin-right: 10rpx;
	}

	//自营
	.demo-tag-owner {
		background: #FF4B44;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 5rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	//以租代售
	.demo-tag-text {
		color: #FFFFFF;
		background: #FFB763;
		border-radius: 5rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		font-size: 20rpx;
		margin-right: 10rpx;
	}

	//一成首付
	.demo-tag-sf {
		color: #FFFFFF;
		background: #FFD053;
		border-radius: 5rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		font-size: 20rpx;
	}

	//巨能降
	.demo-tag-j {
		color: #FFFFFF;
		background: rgb(180, 213, 97);
		border-radius: 5rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 20rpx;
		color: $u-type-error;
		margin-top: 5px;
	}

	//指导价
	.demo-price2 {
		font-size: 22rpx;
		color: rgb(157, 154, 157);
		text-decoration: line-through;
		margin-top: 5px;
	}

	//指导价
	.demo-price3 {
		font-size: 22rpx;
		color: rgb(157, 154, 157);
		margin-top: 5px;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}
</style>
